# -*- coding: utf-8 -*-
# flake8: noqa

from qiniu import Auth, put_file, etag, urlsafe_base64_encode, PersistentFop
import qiniu.config

access_key = 'hCIio2tJI8xJWDouwSdJiuwVcSVrFkAbFize0C-q'
secret_key = 'uGmNZTOyCyvHDbMb16Q7WSbaEtTDSpugBEHW9jq7'

q = Auth(access_key, secret_key)

bucket_name = 'liuhuiying'

key = 'my-python-logo.mp4'

#设置转码参数
fops = 'avthumb/mp4'

#转码是使用的队列名称
pipeline = 'abc'

#可以对转码后的文件进行使用saveas参数自定义命名，当然也可以不指定文件会默认命名并保存在当前空间
saveas_key = urlsafe_base64_encode('liuhuiying:aaa.mp4')
fops = fops+'|saveas/'+saveas_key

#在上传策略中指定
policy={
  'persistentOps':fops,
  'persistentPipeline':pipeline
 }

pfop = PersistentFop(q, bucket_name, pipeline)
ops = [fops]
ret, info = pfop.execute(key, ops, 1)
print(info)
assert ret['persistentId'] is not None